#include <iostream>
#include "Vector.h"

using namespace std;

int main() {
    cout << "Test1:" << endl;
    // 创建一个空的Vector<int>
    Vector<int> v1;

    // 添加元素到Vector中
    cout << "Adding elements to the vector...\n";
    v1.push_back(0);
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);

    // 输出Vector的内容
    cout << "Vector elements:";
    for (int i = 0; i < v1.size(); ++i) {
        cout << " " << v1[i];
    }
    cout << "\n\n";

    // 测试访问元素的方式：使用operator[]和at()
    cout << "Accessing elements:\n";
    cout << "v1[2] = " << v1[2] << endl;
    cout << "v1.at(3) = " << v1.at(3) << endl;
    try {
        cout << "v1.at(4) = " << v1.at(4) << endl;
    } catch (out_of_range& error) {
        cerr << "Exception caught: " << error.what() << endl;
    }
    cout << "\n";

     // 测试Vector的size()和empty()方法
    cout << "Vector size and empty check:\n";
    cout << "v1.size() = " << v1.size() << endl;
    cout << "v1.empty() = " << boolalpha << v1.empty() << endl;
    cout << "\n";
    
    // 清空Vector并再次检查size()和empty()
    cout << "Clearing the vector...\n";
    v1.clear();
    cout << "After clearing:\n";
    cout << "v1.size() = " << v1.size() << endl;
    cout << "v1.empty() = " << boolalpha << v1.empty() << endl;


    cout << "\n\nTest2:" << endl;
    // 创建一个空的Vector<char>
    Vector<char> v2;
    
    // 添加元素到Vector中
    cout << "Adding elements to the vector...\n";
    v2.push_back('a');
    v2.push_back('b');
    v2.push_back('c');
    v2.push_back('d');
    
    // 输出Vector的内容
    cout << "Vector elements:";
    for (int i = 0; i < v2.size(); ++i) {
        cout << " " << v2[i];
    }
    cout << "\n\n";
    
    // 测试访问元素的方式：使用operator[]和at()
    cout << "Accessing elements:\n";
    cout << "v2[2] = " << v2[2] << endl;
    cout << "v2.at(3) = " << v2.at(3) << endl;
    try {
        cout << "v2.at(4) = " << v2.at(4) << endl;
    } catch (out_of_range& error) {
        cerr << "Exception caught: " << error.what() << endl;
    }
    cout << "\n";
    
    // 测试Vector的size()和empty()方法
    cout << "Vector size and empty check:\n";
    cout << "v2.size() = " << v2.size() << endl;
    cout << "v2.empty() = " << boolalpha << v2.empty() << endl;
    cout << "\n";
    
    // 清空Vector并再次检查size()和empty()
    cout << "Clearing the vector...\n";
    v2.clear();
    cout << "After clearing:\n";
    cout << "v2.size() = " << v2.size() << endl;
    cout << "v2.empty() = " << boolalpha << v2.empty() << endl;
    
    return 0;
}
